#include <iostream>
#include <string>
#include <deque>
using namespace std;

//遍历
template <typename T>
void print_deque(deque<T> &d)
{
	for (deque<T>::iterator it = d.begin(); it != d.end(); it++)
	{
		cout << *it << " ";
	}
}

//容器:deque双端数组
void my_deque()
{
	deque<int> d1;
	d1.push_back(1);
	d1.push_back(2);
	d1.push_back(3);

	d1.push_front(-1);
	d1.push_front(-2);
	d1.push_front(-3);
	cout << "头部元素:" << d1.front() << endl;
	cout << "尾部元素:" << d1.back() << endl;
	cout << "大小:" << d1.size() << endl;
	//弹出头部元素
	d1.pop_front();
	//弹出尾部元素
	d1.pop_back();
	cout << "头部元素:" << d1.front() << endl;
	cout << "尾部元素:" << d1.back() << endl;
	cout << "大小:" << d1.size() << endl;

	//遍历
	print_deque(d1);

	//查找元素的下标
	deque<int>::iterator it = find(d1.begin(), d1.end(), 1);
	if (it != d1.end())
	{
		cout << "1的下标是:" << distance(d1.begin(), it) << endl;
	}
	else
	{
		cout << "没找到1这个元素" << endl;
	}
}
void main3()
{
	my_deque();
	system("pause");
	return;
}